package com.xmall.product.utils;

import com.xmall.define.dto.es.EsSkuDto;
import com.xmall.define.dto.es.EsSpuAttr;
import com.xmall.define.dto.log.RetryLogDto;
import com.xmall.define.dto.product.EsBaseAttrDto;
import com.xmall.define.dto.product.SkuAttrDto;
import com.xmall.define.dto.product.SkuImageDto;
import com.xmall.define.dto.product.SkuInfoDto;
import com.xmall.product.define.dto.baseAttr.BaseAttrDo;
import com.xmall.product.define.dto.baseAttr.BaseAttrDto;
import com.xmall.product.define.dto.category.CategoryDto;
import com.xmall.product.define.dto.group.AttrOptionDto;
import com.xmall.product.define.dto.group.GroupDo;
import com.xmall.product.define.dto.group.GroupDto;
import com.xmall.product.define.dto.saleAttr.SaleAttrDo;
import com.xmall.product.define.dto.saleAttr.SaleAttrDto;
import com.xmall.product.define.dto.saleAttr.SpuSaleAttrDo;
import com.xmall.product.define.dto.saleAttr.SpuSaleAttrDto;
import com.xmall.product.define.dto.sku.SkuInfoDo;
import com.xmall.product.define.dto.spu.*;
import com.xmall.product.define.request.attr.BaseAttrUpdateRequest;
import com.xmall.product.define.request.attr.SaleAttrUpdateRequest;
import com.xmall.product.define.request.group.GroupUpdateRequest;
import com.xmall.product.define.request.spu.*;
import com.xmall.product.entity.*;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

public interface ConvertUtils {

    /**
     * 分类
     */
    @Mapper(componentModel = "spring")
    interface CategoryModule {
        CategoryModule INSTANCE = Mappers.getMapper(CategoryModule.class);
        CategoryDto toDto(Category category);
    }

    /**
     * 基本属性
     */
    @Mapper(componentModel = "spring")
    interface BaseAttrModule {
        BaseAttrModule INSTANCE = Mappers.getMapper(BaseAttrModule.class);
        BaseAttrDto do2Dto(BaseAttrDo attrDo);
        BaseAttr toEntity(BaseAttrUpdateRequest request);
        List<EsBaseAttrDto> toEsList(List<BaseAttr> baseAttrList);
        List<BaseAttrDto> doList2DtoList(List<BaseAttrDo> attrDo);
    }

    /**
     * spu基本属性
     */
    @Mapper(componentModel = "spring")
    interface SpuBaseAttrModule {
        SpuBaseAttrModule INSTANCE = Mappers.getMapper(SpuBaseAttrModule.class);
        List<EsSpuAttr> toEsList(List<SpuBaseAttrDto> spuBaseAttrList);
        List<SpuBaseAttrDto> toDtoList(List<SpuBaseAttr> spuBaseAttrList);
        List<SpuBaseAttr> toEntityList(List<SpuBaseAttrRequest> requestList);
    }

    /**
     * spu销售属性
     */
    @Mapper(componentModel = "spring")
    interface SpuSaleAttrModule {
        SpuSaleAttrModule INSTANCE = Mappers.getMapper(SpuSaleAttrModule.class);
        SpuSaleAttr toEntity(SpuSaleAttrRequest request);
        List<SpuSaleAttrDto> doListToDtoList(List<SpuSaleAttrDo> spuSaleAttrDoList);
    }

    /**
     * 属性可选值
     */
    @Mapper(componentModel = "spring")
    interface AttrOptionModule {
        AttrOptionModule INSTANCE = Mappers.getMapper(AttrOptionModule.class);
        AttrOption toEntity(SpuSaleAttrOptionRequest request);
    }

    /**
     * 销售属性
     */
    @Mapper(componentModel = "spring")
    interface SaleAttrModule {
        SaleAttrModule INSTANCE = Mappers.getMapper(SaleAttrModule.class);
        SaleAttrDto do2Dto(SaleAttrDo attrDo);
        SaleAttr toEntity(SaleAttrUpdateRequest request);
        List<SaleAttrDto> doList2DtoList(List<SaleAttrDo> attrDo);
    }

    /**
     * 分组
     */
    @Mapper(componentModel = "spring")
    interface GroupModule {
        GroupModule INSTANCE = Mappers.getMapper(GroupModule.class);
        List<GroupDto> doList2DtoList(List<GroupDo> groupDoList);
        GroupDto doToDto(GroupDo groupDo);
        GroupDto toDto(Group group);
        Group toEntity(GroupUpdateRequest request);
        List<GroupDto> toDtoList(List<Group> groupList);
    }

    /**
     * sku
     */
    @Mapper(componentModel = "spring")
    interface SkuModule {
        SkuModule INSTANCE = Mappers.getMapper(SkuModule.class);
        List<SkuInfoDto> doList2DtoList(List<SkuInfoDo> skuInfoDoList);
        SkuInfo toEntity(SkuInfoRequest request);
        List<SkuInfoDto> dtoList2apiDtoList(List<SkuInfoDto> skuInfoDtoList);
    }

    /**
     * sku attr
     */
    @Mapper(componentModel = "spring")
    interface SkuAttrModule {
        SkuAttrModule INSTANCE = Mappers.getMapper(SkuAttrModule.class);
        List<SkuAttr> toEntityList(List<SkuAttrRequest> requestList);

        List<AttrOptionDto> dtoList2valueList(List<SkuAttrDto> skuAttrDto);
    }

    /**
     * sku image
     */
    @Mapper(componentModel = "spring")
    interface SkuImageModule {
        SkuImageModule INSTANCE = Mappers.getMapper(SkuImageModule.class);
        List<SkuImage> toEntityList(List<SkuImageRequest> requestList);
        List<SkuImageDto> toDtoListFromSpuImage(List<SpuImageDto> spuImageDtoList);
    }

    /**
     * spu desc
     */
    @Mapper(componentModel = "spring")
    interface SpuDescModule {
        SpuDescModule INSTANCE = Mappers.getMapper(SpuDescModule.class);
        List<SpuDescDto> toDtoList(List<SpuDesc> spuDescList);
        List<SpuDesc> toEntityList(List<SpuDescRequest> requestList);
    }

    /**
     * spu image
     */
    @Mapper(componentModel = "spring")
    interface SpuImageModule {
        SpuImageModule INSTANCE = Mappers.getMapper(SpuImageModule.class);
        List<SpuImageDto> toDtoList(List<SpuImage> spuImageList);
        List<SpuImage> toEntityList(List<SpuImageRequest> requestList);
    }

    /**
     * spu
     */
    @Mapper(componentModel = "spring")
    interface SpuModule {
        SpuModule INSTANCE = Mappers.getMapper(SpuModule.class);
        List<EsSkuDto> toEsList(List<SkuInfo> skuList);
        SpuInfoDto toDto(SpuInfo spuInfo);
        List<SpuInfoDto> toDtoList(List<SpuInfo> spuInfoList);
    }

    /**
     * order retry log
     */
    @Mapper(componentModel = "spring")
    interface RetryLogModule {
        RetryLogModule INSTANCE = Mappers.getMapper(RetryLogModule.class);

        RetryLogDto toDtoFromStockDeduct(StockDeductRetryLog stockDeductRetryLog);
        RetryLogDto toDtoFromStockRevert(StockRevertRetryLog stockRevertRetryLog);
    }
}
